import express from 'express'
import { ExpressValidator, ValidationError } from 'express-validator'
export const { check, body, cookie, header, param, query, checkExact, checkSchema, matchedData, oneOf, validationResult } = new ExpressValidator(
    {},
    {},
    {
        errorFormatter: (error: any) => {
            return { path: error?.path, msg: error.msg }
        },
    });


export const validate = () => {
    return async (req: express.Request, res: express.Response, next: express.NextFunction) => {
        const result = validationResult(req)
        if (result.isEmpty()) {
            next()
        } else {
            next(result)
        }


    };
}